//此文件是用来实现tab键的格式化代码的功能
//window的tab太他妈苟了
let $div = $(document.activeElement);
document.onkeydown = function HandleTabKey(evt) {
    if (evt.keyCode == 9) {
        if (evt.preventDefault) {
            evt.preventDefault();
        } else {
            evt.returnValue = false;
        }
        $div.value = $div.value + "    ";
    }
}
//textarea支持tab缩进
$("textarea").on(
    'keydown',
    function (e) {
        if (e.keyCode == 9) {
            e.preventDefault();
            let indent = '    ';
            let start = this.selectionStart;
            let end = this.selectionEnd;
            let selected = window.getSelection().toString();
            selected = indent + selected.replace(/\n/g, '\n' + indent);
            this.value = this.value.substring(0, start) + selected
                + this.value.substring(end);
            this.setSelectionRange(start + indent.length, start
                + selected.length);
        }
    })